package cn.itcast.flink.base;

        import org.apache.flink.api.common.restartstrategy.RestartStrategies;
        import org.apache.flink.streaming.api.datastream.DataStreamSource;
        import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * Author itcast
 * Date 2021/7/27 10:19
 * 读取文件数据
 */
public class FileSource {
    public static void main(String[] args) throws Exception {
/*        System.setProperty("hadoop.home.dir","C:\\hadoop2.7.5");
        System.setProperty("HADOOP_USER_NAME", "root");*/
        //1.创建流执行环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setRestartStrategy(RestartStrategies.fixedDelayRestart(3,3000));
        //2.读取本地文件
        //todo 2.1读取本文文本文件
        DataStreamSource<String> source = env.readTextFile("data/test.txt");
        //todo 2.2读取压缩文件
        DataStreamSource<String> zipSource = env.readTextFile("data/hello.txt.gz");
        //todo 2.3读取HDFS文件
        //DataStreamSource<String> hdfsSource = env.readTextFile("hdfs://node1:8020/words.txt");
        DataStreamSource<String> socketStream = env.socketTextStream("node1", 9999);
        //3.打印输出
        //source.print();
        //zipSource.print("zip file ");
        //hdfsSource.print();
        socketStream.print();
        //4.执行流环境
        env.execute();
    }
}
